package com.metaera.app.widget;

import android.util.Log;

import com.metaera.app.controller.view.core.IStatusView;
import com.orhanobut.logger.Logger;

import and.fast.statelayout.StateLayout;

public class LayoutRequestStatusView implements IStatusView {

    private StateLayout mStateLayout;

    public LayoutRequestStatusView(StateLayout layout) {
        this.mStateLayout = layout;
    }

    @Override
    public void loading() {
        if (mStateLayout == null) {
            Logger.i("LayoutRequestStatusView", "loading, 状态布局未初始化");
            return;
        }

        mStateLayout.showStateView(StateLayout.LOADING_STATE);
    }

    @Override
    public void offline() {
        if (mStateLayout == null) {
            Logger.i("LayoutRequestStatusView", "offline, 状态布局未初始化");
            return;
        }

        mStateLayout.showStateView(StateLayout.OFFLINE_STATE);
    }

    @Override
    public void failure(Throwable throwable) {
        if (mStateLayout == null) {
            Logger.i("LayoutRequestStatusView", "failure, 状态布局未初始化");
            return;
        }

//        if (throwable instanceof UnauthorizedException) {
//            UnauthorizedDialog.show(mStateLayout.getContext(), throwable.getMessage());
//
//        } else {
            mStateLayout.showStateView(StateLayout.FAILURE_STATE, throwable.getMessage() + "\n");
//        }

    }

    @Override
    public void complete() {
        if (mStateLayout == null) {
            Log.i("LayoutRequestStatusView", "complete, mStateLayout == null");
            return;
        }

        mStateLayout.showContentView();
    }

    @Override
    public void empty(CharSequence charSequence) {
        if (mStateLayout == null) {
            Log.i("LayoutRequestStatusView", "empty, mStateLayout == null");
            return;
        }

        mStateLayout.showStateView(StateLayout.EMPTY_STATE, charSequence);
    }

}
